package com.edmendst.xmall.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Value("${product.image}")
    private String productImagePath;

    @Value("${upload.path}")
    private String userImagePath;

    @Value("${shop.logo}")
    private String shopImagePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        System.out.println("WebConfig 初始化成功！");
        System.out.println("商品图片映射路径：" + "file:" + productImagePath); // 添加日志
        // 商品图片映射：通过 /product_images/** 访问
        registry.addResourceHandler("/product_images/**")
                .addResourceLocations("file:" + productImagePath);

        // 用户头像映射：通过 /user_images/** 访问
        registry.addResourceHandler("/user_images/**")
                .addResourceLocations("file:" + userImagePath);

        // 店铺图片映射：通过 /shop_images/** 访问
        registry.addResourceHandler("/shop_images/**")
                .addResourceLocations("file:" + shopImagePath);
    }
}